package com.itheima.stock;

import com.itheima.stock.StockApp;
import com.itheima.stock.utils.DateTimeUtil;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest(classes = StockApp.class)
public class Dome01 {

    @Test
    public void Test01() {
//        DateTime dateTime = new DateTime();
        DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
//        DateTime dateTimett = dateTimeFormatter.parseDateTime("2022-01-01");
////        long millis = dateTime1.getMillis();
////        System.out.println(millis);


//        DateTime dateTime = new DateTime();
//        String dateTime1 = dateTime.dayOfMonth().withMinimumValue().toString(dateTimeFormatter);
//        String dateTime2 = dateTime.dayOfMonth().withMaximumValue().toString(dateTimeFormatter);
//        System.out.println(dateTime1);
//        System.out.println(dateTime2);


//        int dayOfMonth = dateTime.getDayOfMonth();
        //传入的时间
        String chuTIme = "2022-02-22 13:00:01";
//        DateTime chuTIme1 = dateTimeFormatter.parseDateTime(chuTIme);
//        System.out.println(chuTIme1);
//        String dingTime = "2022-02-22 11:28:00";
//        DateTime dingTime2 = dateTimeFormatter.parseDateTime(dingTime);
//        System.out.println(dingTime2);
//        int seconds = Seconds.secondsBetween(chuTIme1, dingTime2).getSeconds();
//
//        System.out.println(seconds);

        //先获取当前时间的星期
        int dateTime = dateTimeFormatter.parseDateTime(chuTIme).getDayOfWeek();
        //当前时间
        DateTime dateTime1 = dateTimeFormatter.parseDateTime(chuTIme);
        if ((dateTime1.getHourOfDay() > 9 && dateTime1.getMinuteOfHour() > 30) && (dateTime1.getHourOfDay() < 11 && dateTime1.getMinuteOfHour() < 30)
                || (dateTime1.getHourOfDay() > 13 && dateTime1.getMinuteOfHour() > 00) && (dateTime1.getHourOfDay() < 15 && dateTime1.getMinuteOfHour() < 00)
        ) {

        }
        if (dateTime == 1 || dateTime == 2 || dateTime == 3 || dateTime == 4 || dateTime == 5) {
            //获取时间算是否大于上午开盘时间和下午闭盘时间
            //如果当前时间在9:30之前-时间跳转到前一天的的2:58分
            if ((dateTime1.getHourOfDay() < 9 && dateTime1.getMinuteOfHour() < 30) && (dateTime1.getHourOfDay() >0 && dateTime1.getMinuteOfHour() >01) ){
                //天数减
                //获取当前时间的年月日
                int year = dateTime1.getYear();
                int monthOfYear = dateTime1.getMonthOfYear();
                int dayOfMonth = dateTime1.getDayOfMonth() - 1;
                DateTime xingTime = new DateTime(year, monthOfYear, dayOfMonth, 14, 58, 00);
            } else if ((dateTime1.getHourOfDay() > 11 && dateTime1.getMinuteOfHour() > 30) && (dateTime1.getHourOfDay() < 13)) {
                int year = dateTime1.getYear();
                int monthOfYear = dateTime1.getMonthOfYear();
                int dayOfMonth = dateTime1.getDayOfMonth();
                DateTime xingTime = new DateTime(year, monthOfYear, dayOfMonth, 11, 28, 00);
            } else {
                int year = dateTime1.getYear();
                int monthOfYear = dateTime1.getMonthOfYear();
                int dayOfMonth = dateTime1.getDayOfMonth();
                DateTime xingTime = new DateTime(year, monthOfYear, dayOfMonth, 14, 58, 00);
            }
        } else if (dateTime == 6) {
            int year = dateTime1.getYear();
            int monthOfYear = dateTime1.getMonthOfYear();
            int dayOfMonth = dateTime1.getDayOfMonth() - 1;
            DateTime xingTime = new DateTime(year, monthOfYear, dayOfMonth, 14, 58, 00);
        } else {
            int year = dateTime1.getYear();
            int monthOfYear = dateTime1.getMonthOfYear();
            int dayOfMonth = dateTime1.getDayOfMonth() - 2;
            DateTime xingTime = new DateTime(year, monthOfYear, dayOfMonth, 14, 58, 00);
        }


    }


    @Test
    public void Test02() {
        DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
        String chuTIme = "2022-02-22 13:00:01";
        DateTime dateTime = dateTimeFormatter.parseDateTime(chuTIme);
        String shi1="2022-02-22 13:00:01";
        int hourOfDay = dateTime.getHourOfDay();
        System.out.println(hourOfDay);
    }


    @Test
    public void Test03() {
        DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
        DateTime dateTime = dateTimeFormatter.parseDateTime("2022-02-22 09:00:01");
        //获取当前时间的年月日
        int year = dateTime.getYear();
        System.out.println(year);
        int monthOfYear = dateTime.getMonthOfYear();
        System.out.println(monthOfYear);
        int dayOfMonth = dateTime.getDayOfMonth() - 1;
        System.out.println(dayOfMonth);
        int hourOfDay = dateTime.getHourOfDay();
        System.out.println(hourOfDay);
        int minuteOfHour = dateTime.getMinuteOfHour();
        System.out.println(minuteOfHour);
        DateTime dateTime1 = new DateTime(year, monthOfYear, dayOfMonth, 14, 58, 00);
        System.out.println(dateTime1);

    }







    @Test
    public Object Test04(String chuTIme) {
        DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
        int dateTime = dateTimeFormatter.parseDateTime(chuTIme).getDayOfWeek();
        //当前时间
        DateTime dateTime1 = dateTimeFormatter.parseDateTime(chuTIme);
        if ((dateTime1.getHourOfDay() >= 9 && dateTime1.getMinuteOfHour() > 30) && (dateTime1.getHourOfDay() < 11 && dateTime1.getMinuteOfHour() < 30)
                || (dateTime1.getHourOfDay() >= 13 && dateTime1.getMinuteOfHour() > 00) && (dateTime1.getHourOfDay() <= 15 && dateTime1.getMinuteOfHour() < 00)
        ) {
            return chuTIme;
        }



        if (dateTime == 1 || dateTime == 2 || dateTime == 3 || dateTime == 4 || dateTime == 5) {
            //获取时间算是否大于上午开盘时间和下午闭盘时间
            //如果当前时间在9:30之前-时间跳转到前一天的的2:58分
            if (dateTime1.getHourOfDay() <= 9 && dateTime1.getMinuteOfHour()<30){
                //天数减
                //获取当前时间的年月日
                int year = dateTime1.getYear();
                int monthOfYear = dateTime1.getMonthOfYear();
                int dayOfMonth = dateTime1.getDayOfMonth() -1;
                DateTime dateTime2 = new DateTime(year, monthOfYear, dayOfMonth, 14, 58, 00);
                String s = dateTime2.toString(dateTimeFormatter);
                return s;
            } else if ((dateTime1.getHourOfDay() >= 11 && dateTime1.getMinuteOfHour() > 30) && (dateTime1.getHourOfDay() <= 13)) {
                int year = dateTime1.getYear();
                int monthOfYear = dateTime1.getMonthOfYear();
                int dayOfMonth = dateTime1.getDayOfMonth();
                DateTime dateTime2 = new DateTime(year, monthOfYear, dayOfMonth, 11, 28, 00);
                String s = dateTime2.toString(dateTimeFormatter);
                return s;
            } else {
                int year = dateTime1.getYear();
                int monthOfYear = dateTime1.getMonthOfYear();
                int dayOfMonth = dateTime1.getDayOfMonth();
                DateTime dateTime2 = new DateTime(year, monthOfYear, dayOfMonth, 14, 58, 00);
                String s = dateTime2.toString(dateTimeFormatter);
                return s;
            }
        } else if (dateTime == 6) {
            int year = dateTime1.getYear();
            int monthOfYear = dateTime1.getMonthOfYear();
            int dayOfMonth = dateTime1.getDayOfMonth() - 1;
            DateTime dateTime2 = new DateTime(year, monthOfYear, dayOfMonth, 14, 58, 00);
            String s = dateTime2.toString(dateTimeFormatter);
            return s;
        } else {
            int year = dateTime1.getYear();
            int monthOfYear = dateTime1.getMonthOfYear();
            int dayOfMonth = dateTime1.getDayOfMonth() - 2;
            DateTime dateTime2 = new DateTime(year, monthOfYear, dayOfMonth, 14, 58, 00);
            String s = dateTime2.toString(dateTimeFormatter);
            return s;
        }

    }


    @Test
    public void Test05() {
        System.out.println(DateTimeUtil.getLastDateString4Stock(DateTime.now()));
    }








}
